var ctx;
var ownerName = "";
var lname = "";
var phoneNo = "";
var pSize;

function setCtx(ctx){
	this.ctx = ctx;
}

function gotoPage(page){
	ownerName = ifNull($("#ownerName").val());
	lName = ifNull($("#lName").val());
	phoneNo = ifNull($("#phoneNo").val());
	pSize = ifNull($("#pSize").val());
	//解决ie9以下placeholder与value重复的问题
	if(ownerName == $("#ownerName").attr("placeholder")){
		ownerName = "";
	}
	if(lName == $("#lName").attr("placeholder")){
		lName = "";
	}
	if(phoneNo == $("#phoneNo").attr("placeholder")){
		phoneNo = "";
	}
	loadContent("/ownerinfo/ownerInfoList?pNo="+ page +"&name="+ ownerName +"&lName="+ lName +"&phoneNo="+ phoneNo + "&pSize="+ pSize);
}

function ifNull(mess){
	if(mess == null || mess == undefined){
		mess = "";
	}
	
	return mess;
}

//条件搜索用户列表
function getOwnerInfoList(){
	ownerName = ifNull($("#ownerName").val());
	lName = ifNull($("#lName").val());
	phoneNo = ifNull($("#phoneNo").val());
	pSize = ifNull($("#pSize").val());
	//解决ie9以下placeholder与value重复的问题
	if(ownerName == $("#ownerName").attr("placeholder")){
		ownerName = "";
	}
	if(lName == $("#lName").attr("placeholder")){
		lName = "";
	}
	if(phoneNo == $("#phoneNo").attr("placeholder")){
		phoneNo = "";
	}
	loadContent("/ownerinfo/ownerInfoList?pNo=1&name="+ ownerName +"&lName="+ lName +"&phoneNo="+ phoneNo + "&pSize="+ pSize);
	
}

function gotoOwnerInfoPage(page) {
	if(page == null){
		page = $(".inputclass").val();
	}
	ownerName = ifNull($("#ownerName").val());
	lName = ifNull($("#lName").val());
	phoneNo = ifNull($("#phoneNo").val());
	pSize = ifNull($("#pSize").val());
	//解决ie9以下placeholder与value重复的问题
	if(ownerName == $("#ownerName").attr("placeholder")){
		ownerName = "";
	}
	if(lName == $("#lName").attr("placeholder")){
		lName = "";
	}
	if(phoneNo == $("#phoneNo").attr("placeholder")){
		phoneNo = "";
	}
	loadContent("/ownerinfo/ownerInfoList?pNo="+ page +"&name="+ ownerName +"&lName="+ lName +"&phoneNo="+ phoneNo + "&pSize="+ pSize);
}

/**
 * 业主信息详情
 * @param id
 */
function ownerInfoDetail (id) {
	loadContent("/ownerinfo/ownerInfoDetail?id="+id+"");
}

function approved(id, state) {
	var message;
	switch (parseInt(state)) {
	case 1:
		message = "是否禁用？";
		break;
	case 2:
		message = "是否启用？";
		break;
	default:
		break;
	}
	layer.confirm(message, {
		icon : 3,
		title : '提示'
	}, function(index) {
		$.ajax({
			type : "POST",
			url : ctx + "/ownerinfo/ownerInfoUpdate",
			cache : false,
			dataType : 'json',
			data : {
				id : id,
				state : state
			},
			success : function(result) {
				if (result.success) {
					layer.msg("操作成功", {
						icon : 1,
						time : 1000
					// 2秒关闭（如果不配置，默认是3秒）
					}, function() {
						if (state == 1) {
							loadContent("/ownerinfo/newOwnerInfoList");
						} else {
							loadContent("/ownerinfo/ownerInfoList");
						}

					});
				} else {
					layer.msg("操作失败", {
						icon : 2
					});
				}
			}
		});
		layer.close(index);
	});
}

function unapproved(id, state) {
	var statechange;
	if (state == 1) {
		statechange = 5;
	}
	layer.confirm('是否驳回？', {
		icon : 3,
		title : '提示'
	}, function(index) {
		$.ajax({
			type : "POST",
			url : ctx + "/ownerinfo/ownerInfoUpdate",
			cache : false,
			dataType : 'json',
			data : {
				id : id,
				state : statechange
			},
			success : function(result) {
				if (result.success) {
					layer.msg("操作成功", {
						icon : 1,
						time : 1000
					// 2秒关闭（如果不配置，默认是3秒）
					}, function() {
						if (state == 1) {
							loadContent("/ownerinfo/newOwnerInfoList");
						} else {
							loadContent("/ownerinfo/ownerInfoList");
						}

					});
				} else {
					layer.msg("操作失败", {
						icon : 2
					});
				}
			}
		});
		layer.close(index);
	});
}

//鼠标滑入一行改变背景颜色
function mouseoverOne(target){
	 $(target).children().each(function(){
		  	    $(this).css("background","#D3F0F1");
		     });
}

//鼠标滑出一行恢复原来的背景颜色
function mouseoutOne(target){
	 $(target).children().each(function(){
	  	    $(this).css("background","");
	     });
}



